package com.sike.handler;

import com.alibaba.fastjson.JSON;

import com.sike.common.result.AuthResult;
import com.sike.common.result.Result;
import com.sike.common.result.ResultCode;
import com.sike.common.utils.WebUtils;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;


import java.io.IOException;


@Component
public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) throws IOException {

        AuthResult result = new AuthResult(ResultCode.UNAUTHORIZED.getCode(), "用户认证失败请查询登录",null);
        String jsonString = JSON.toJSONString(result);
        WebUtils.renderString(response,jsonString);
    }
}
